<?php
	use\ampleharvest\code\cConfig;
	/**
	 * Includes Path Info Class
	 */
	require_once(dirname(dirname(__FILE__))) . '/config/cConfig.php';
	$codeConfig = new \ampleharvest\code\cConfig();
	
	require_once 'Tables/cTABLE_Log.php';

	require_once $codeConfig->C_STR_LOG_LIB_PATH . "/Abstract_Classes/abs_Log.php";

	class cAmpleHarvestLog extends \abs_Log
	{
		/**
		 * @{
		 * @name Debug Level Options
		 * @brief Debug Level Options
		 */
		const C_INT_LEVEL_NONE = 0;
		const C_INT_LEVEL_ERRORS = 25;
		const C_INT_LEVEL_INFO = 50;
		const C_INT_LEVEL_DEBUG = 100;
		const C_INT_LEVEL_HIDDEN = 200;
		/**@}*/

		/**
		 * @{
		 * @name Actions Options
		 * @brief Actions Specific To Ample Harvest
		 */
		const C_STR_ACTION_DATA_INDEX_INFO = "Data Index Info";
		const C_STR_ACTION_DATA_INDEX_ERROR = "Data Index Error";
		const C_STR_ACTION_DATA_PROC_1_INFO = "Data Processing Stage 1 Info";
		const C_STR_ACTION_DATA_PROC_1_ERROR = "Data Processing Stage 1 Error";
		const C_STR_ACTION_EMAIL_INFO = "Email Info";
		const C_STR_ACTION_EMAIL_ERROR = "Email Error";
		const C_STR_ACTION_QUERY_NOTIFICATION_INFO = "Query Notification Info";
		const C_STR_ACTION_QUERY_NOTIFICATION_ERROR = "Query Notification Error";
		const C_STR_ACTION_STOMP_INFO = "STOMP Info";
		const C_STR_ACTION_STOMP_ERROR = "STOMP Error";
		const C_STR_ACTION_TASK_INFO = "Task Info";
		const C_STR_ACTION_TASK_ERROR = "Task Error";

		/**@}*/
		protected $m_obj_TABLE_Log = null;

		protected $m_str_Proc_ID = "";

		/**
		 * Set default Log Settings
		 */
		public function __construct()
		{
			$this->set_LogLevel(cConfig::C_INT_LOG_LEVEL);
			$this->set_LogFormat(self::C_INT_LOG_FORMAT_DATABASE);
			$this->activate();

			$this->m_obj_TABLE_Log = new cTABLE_Log();
		}

		public function get_ProcID()
		{
			if (!$this->m_str_Proc_ID)
			{
				$this->m_str_Proc_ID = uniqid();
			}

			return $this->m_str_Proc_ID;
		}

		/**
		 * Outputs Log information to a file
		 * @param string $str_LogType Type of Action being loged
		 * @param string $str_LogData Text to be writen to log
		 * @return integer
		 * <ul>
		 * 		<li>
		 * 			-2 - could not connect to database
		 * 		</li>
		 * 		<li>
		 * 			0 - Success
		 * 		</li>
		 * </ul>
		 */
		protected function do_DBLog($str_LogType, $str_LogData)
		{
			$this->m_obj_TABLE_Log->clear();

			$this->m_obj_TABLE_Log->set_msg($str_LogData);
			$this->m_obj_TABLE_Log->set_proc_id($this->get_ProcID());
			$this->m_obj_TABLE_Log->set_type($str_LogType);
			$this->m_obj_TABLE_Log->set_timestamp(date("Y-m-d H:i:s"));

			if ($this->m_obj_TABLE_Log->save_Data2DB())
			{
				return 0;
			}

			return -2;
		}
	}
